"use strict";

const Controller = require("egg").Controller;
const jwt = require("jsonwebtoken");
// const fs = require("fs");
const Mock = require("mockjs");

const Data = require("../../mock/newdata(4).json");

class PcController extends Controller {
    // 插入订单管理数据;
    async insertDingDan() {
        const { ctx, app } = this;
        await app.mysql.insert("dingdan", Data);

        ctx.body = {
            msg: "h1,egg",
        };
    }

    // 获取订单管理数据;
    async getDingDanList() {
        const { ctx, app } = this;
        const { current, size } = ctx.request.body;
        const data = await app.mysql.query(
            `select * from dingdan limit ${(current - 1) * size},${size}`
        );

        ctx.body = {
            msg: "h1,egg",
            data,
        };
    }

    // 获取pc端的所有用户信息数据
    async pcUserList() {
        const { ctx, app } = this;
        const data = await app.mysql.select("pclogin");
        ctx.body = {
            code: "200",
            data,
        };
    }

    // 改变权限
    async pcUserAuth() {
        const { ctx, app } = this;
        const { auth, id } = ctx.request.body;
        console.log(auth, id);

        const data = await app.mysql.update("pclogin", { auth: auth, id: id });
        ctx.body = {
            code: "200",
            data,
        };
    }
}

module.exports = PcController;